package cn.train.controler;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.train.model.UserTable;
import cn.train.service.UserTableService;


@WebServlet("/UserLoginServlet")
public class UserLoginServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String uname = req.getParameter("username");
		String upass = req.getParameter("password");

		UserTableService userService=new UserTableService();
		UserTable usertable = userService.login(uname, upass);
		resp.setContentType("text/html;charSet=utf-8");
		PrintWriter out =resp.getWriter();
		if (usertable != null) {
			req.getSession().setAttribute("usertable", usertable);
			req.getRequestDispatcher("font/index.jsp").forward(req, resp);
		} else {
			out.print("<script>alert('账号密码错误，或者账号被冻结');location.href='font/login.jsp'</script>");
			
		}
		
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req,resp);
	}

}
